package edu.gatech.oops.servlets;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ViewUsers, which goes into the database(text file for now),
 * and prints off all of the users in the database/textfile.
 */
public class ViewUsers extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewUsers() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");
		File file = new File("/home/pushkara/workspace/LabAssistan/Data.txt");
		BufferedReader reader = new BufferedReader(new FileReader(file));
		String line = reader.readLine();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>USERESSSS AWWW YEEEEEEEAH</title>");
		out.println("</head>");
		
		out.println("<body>");
		out.println("<h2>List of Users</h2>");
		while(line!=null){
			String[] data = line.split(",");
			out.println(data[2]+" ");
			line = reader.readLine();
		}
		out.close();
		
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request,response);
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request,response);
		// TODO Auto-generated method stub
	}

}
